package com.yxhl.zoume.core.busticket.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.yxhl.zoume.R;
import com.yxhl.zoume.common.ui.activity.base.BaseActivityWithToolBar;
import com.yxhl.zoume.core.busticket.model.TicketsQueryOptions;
import com.yxhl.zoume.core.busticket.ui.fragment.BusServicesQueryFragment;
import com.yxhl.zoume.di.component.base.HasComponent;
import com.yxhl.zoume.di.component.busticket.BusServiceComponent;
import com.yxhl.zoume.di.component.busticket.DaggerBusServiceComponent;
import com.yxhl.zoume.di.module.busticket.BusServiceModule;

/**
 * 巴士车票列表
 * Created by Xboy on 16/3/16.
 */
public class BusServicesQueryActivity extends BaseActivityWithToolBar implements HasComponent<BusServiceComponent> {
    private static final String KEY_QUERY_OPTIONS = "QUERY_OPTIONS_ACTIVITY";

    private TicketsQueryOptions mQueryOptions;

    // Injector
    private BusServiceComponent component;

    /**
     * intent for navigation
     *
     * @param context
     * @param options
     * @return
     */
    public static Intent getCallingIntent(Context context, TicketsQueryOptions options) {
        Intent callingIntent = new Intent(context, BusServicesQueryActivity.class);
        callingIntent.putExtra(KEY_QUERY_OPTIONS, options);
        return callingIntent;
    }

    private void handleIntent() {
        Intent intent = getIntent();
        if (null != intent) {
            Bundle bundle = intent.getExtras();
            mQueryOptions = (TicketsQueryOptions) bundle.getSerializable(KEY_QUERY_OPTIONS);
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        handleIntent();
        initializeShow();
    }

    private void initializeShow() {
        if (mQueryOptions != null) {
            addFragment(R.id.bus_tickets_query_container, BusServicesQueryFragment.newInstance(mQueryOptions));
        }
    }

    @Override
    protected void onHeaderLeftClick(View view) {
        onBackPressed();
    }

    @Override
    protected void onHeaderRightClick(View view) {

    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_bus_tickets_query;
    }


    @Override
    protected void initializeInjector() {
        this.component = DaggerBusServiceComponent.builder()
                .appComponent(getAppComponent())
                .activityModule(getActivityModule())
                .busServiceModule(new BusServiceModule())
                .build();
    }

    @Override
    public BusServiceComponent getComponent() {
        return component;
    }
}
